<template>
    <div>
        <input type="text" placeholder="用户名" v-model="username">
        <input type="text" placeholder="密码" v-model="password">
        <button @click="login">登录</button>
    </div>
</template>
<script>
export default {
    data(){
        return {
            username:'',
            password:''
        }
    },
    methods:{
        login(){
            this.$http.post('/api/login',{username:this.username,password:this.password}).then(res => {
                if(res.data.code === 1){
                    //token  userinfo  //跳路由
                    let {token,rolename} = res.data;
                    localStorage.setItem('token',token);
                    localStorage.setItem('userinfo',JSON.stringify({username:this.username,rolename}))
                    this.$router.push('/main')
                }else{
                    alert(res.data.msg)
                }
            })
        }
    }
}
</script>
